package com.hs.biye.controller.admin;

import com.hs.biye.constant.MessageConstant;
import com.hs.biye.excepction.BaseException;
import com.hs.biye.model.DTO.RegnusRequest;
import com.hs.biye.model.VO.RegnusVo;
import com.hs.biye.model.reslut.Result;
import com.hs.biye.model.reslut.ResultPage;
import com.hs.biye.service.PatientService;
import com.hs.biye.service.RegnusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/admin/regnus")
@Slf4j
public class RegunsController {

    @Resource
    private RegnusService regnusService;


    @PostMapping("/pages")
    public ResultPage<RegnusVo> getPagesRegnus(@RequestBody RegnusRequest regnusRequest){
        if (regnusRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        ResultPage<RegnusVo> pagePatient = regnusService.getPageRegnus(regnusRequest);
        if (pagePatient == null){
            return ResultPage.faile(MessageConstant.NOT_QUERY);
        }
        return pagePatient;
    }

    @PostMapping("/delete")
    public Result<Boolean> deleteRegnus(@RequestBody RegnusRequest regnusRequest){
        if (regnusRequest== null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        Boolean b = regnusService.deleteReRegnus(regnusRequest);
        return Result.success(b);
    }

    @PostMapping("/add")
    public Result<Boolean> addRegnus(@RequestBody RegnusRequest regnusRequest){
        if (regnusRequest== null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        Boolean b = regnusService.addReRegnus(regnusRequest);
        return Result.success(b);
    }

    @PostMapping("/update")
    public Result<Boolean> updateRegnus(@RequestBody RegnusRequest regnusRequest){
        if (regnusRequest== null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        Boolean b = regnusService.updateReRegnus(regnusRequest);
        return Result.success(b);
    }

    @GetMapping("/getone/{id}")
    public Result<RegnusVo> getOneById(@PathVariable Integer id ){
        if (id== null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        RegnusVo regnusVo = regnusService.getRegnusByid(id);
        return Result.success(regnusVo);
    }
}
